// BattleLineView.cpp : implementation of the CBattleLineView class
//

#include "stdafx.h"
#include "BattleLine.h"

#include "BattleLineDoc.h"
#include "BattleLineView.h"

#include "BattleLine/GameBattleLine.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CBattleLineView

IMPLEMENT_DYNCREATE(CBattleLineView, CView)

BEGIN_MESSAGE_MAP(CBattleLineView, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_WM_TIMER()
	ON_WM_CREATE()
	ON_WM_DESTROY()
END_MESSAGE_MAP()

// CBattleLineView construction/destruction

CBattleLineView::CBattleLineView()
{
	// TODO: add construction code here

}

CBattleLineView::~CBattleLineView()
{

}

BOOL CBattleLineView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CBattleLineView drawing

void CBattleLineView::OnDraw(CDC* /*pDC*/)
{

	CBattleLineDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
}


// CBattleLineView printing

BOOL CBattleLineView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CBattleLineView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CBattleLineView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

// CBattleLineView diagnostics

#ifdef _DEBUG
void CBattleLineView::AssertValid() const
{
	CView::AssertValid();
}

void CBattleLineView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CBattleLineDoc* CBattleLineView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBattleLineDoc)));
	return (CBattleLineDoc*)m_pDocument;
}
#endif //_DEBUG


// CBattleLineView message handlers

void CBattleLineView::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == 0)
	{
		m_pBoardGame->Update( 1.0f/60.0f);
		m_pBoardGame->Render();
		//SendMessage(WM_PAINT,NULL,NULL);		
	}

	CView::OnTimer(nIDEvent);
}

int CBattleLineView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here

	return 0;
}

void CBattleLineView::OnDestroy()
{
	CView::OnDestroy();

	// TODO: Add your message handler code here
	if(m_pBoardGame != NULL)
	{
		m_pBoardGame->Deinit();
		delete m_pBoardGame;
	}
}

void CBattleLineView::OnInitialUpdate()
{
	CView::OnInitialUpdate();
	HWND hWnd = this->GetSafeHwnd();

	// TODO: Add your specialized code here and/or call the base class
	m_pBoardGame = new CGameBattleLine();
	((CGameBattleLine*)m_pBoardGame)->Init(hWnd);

	CBattleLineView::SetTimer( 0 ,1.0f/60.0f ,NULL);
}
